#!/usr/bin/env python
#-*-coding=utf-8-*-

import sys, os, tarfile

if __name__ == '__main__':
    if len(sys.argv) < 2:
        print u"pack_fdl正确用法为:\npython pack_fdl.py 目录名 [目录名...]"
        sys.exit(0)
    for dirname in sys.argv[1:]:
        if not os.path.isdir(dirname):
            print u'! 忽略%s, 因为它不是一个目录名' % dirname
            continue
        if dirname.endswith(os.path.sep):
            dirname = dirname[:-1]
        fdl_filename = "builtin/%s.edo" % dirname
        tf = tarfile.open(fdl_filename, 'w:gz')
        for f in os.listdir(dirname):
            tf.add(os.path.join(dirname, f), f)
        print u"* 创建文件 %s" % fdl_filename
        tf.close()
